//
//  SISSPublicSingleton.m
//  SISSAPP
//
//  Created by 优房网 on 2017/8/30.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSPublicSingleton.h"

@implementation SISSPublicSingleton

+ (instancetype)shared {
    
    static SISSPublicSingleton *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];

        if (UI_IS_IPHONE5) {
            instance.keyboardHeight = 253;
        } else if (UI_IS_IPHONE6) {
            instance.keyboardHeight = 258;
        } else if (UI_IS_IPHONE6PLUS) {
            instance.keyboardHeight = 271;
        } else if (UI_IS_IPHONE_X) {
            instance.keyboardHeight = 299;
        }
    });
    return instance;
}

- (void)shareWithTitle:(NSString *)title descr:(NSString *)descr webpageUrl:(NSString *)webpageUrl currentViewController:(id)currentViewController thumImage:(id)thumImage {
    
    WeakSelf
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根据获取的platformType确定所选平台进行下一步操作
        //            [self shareTextToPlatformType:platformType];
        
        if (platformType == UMSocialPlatformType_Sina) {
            [weakSelf shareImageAndTextToPlatformType:platformType title:(NSString *)title descr:descr webpageUrl:webpageUrl currentViewController:currentViewController thumImage:thumImage];
        }else{
            [weakSelf shareTextToPlatformType:platformType title:(NSString *)title descr:descr webpageUrl:webpageUrl currentViewController:currentViewController thumImage:thumImage];
        }
    }];
}


- (void)shareImageAndTextToPlatformType:(UMSocialPlatformType)platformType title:(NSString *)title descr:(NSString *)descr webpageUrl:(NSString *)webpageUrl currentViewController:(id)currentViewController thumImage:(id)thumImage {
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    
    messageObject.text = @"深圳市优房网络科技有限公司www.szfzx.org";
    
    //创建图片内容对象
    UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
    //如果有缩略图，则设置缩略图
    shareObject.thumbImage = [UIImage imageNamed:@"头像"];
    [shareObject setShareImage:[UIImage imageNamed:@"bg"]];
    
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:currentViewController completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}



- (void)shareTextToPlatformType:(UMSocialPlatformType)platformType title:(NSString *)title descr:(NSString *)decsr webpageUrl:(NSString *)webpageUrl currentViewController:(id)currentViewController thumImage:(id)thumImage {
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //设置文本
    messageObject.text = @"交易通-房源";
    
    //创建网页内容对象
    NSString* thumbURL =  thumImage;
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:decsr thumImage: thumImage ? thumbURL : [UIImage imageNamed:@"头像"]];
    //设置网页地址
    shareObject.webpageUrl = webpageUrl;
    
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:currentViewController completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}




@end
